using Core.Contracts.Interfaces;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using System.Linq;

    
    public sealed class CriticalHitChance<T> : FeatureBase<object>
    {
        public CriticalHitChance(){}

        public CriticalHitChance(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Critical hit chance"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.General; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.CriticalHitChance; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_percent; } }

        /// <summary>
        /// Calculate the modified feature value
        /// </summary>
        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            double temp =
                agent.Extensions.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType)
                +
                robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType);

            ModifiedValue = temp;
        }

        public override string FormattedValue
        {
            get { return String.Format("{0} {1}", IsModified ? (double)ModifiedValue * 100 : (double)Value * 100, Unit); }
        }
    }
}